package com.xixi.demo.model;

import com.xixi.demo.enums.ResultCodeEnum;
import lombok.Data;

/**
 * 返回结果类型
 * @param <T>
 */
@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> Result success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setData(data);
        return result;
    }

    public static <T> Result fail(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        return result;
    }
    public static <T> Result fail(String msg){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMsg(msg);
        return result;
    }
    public static <T> Result noLogin(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO_LOGIN.getCode());
        result.setMsg("未登录");
        return result;
    }

    public static <T> Result noUserNameOrPassword(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO_USERNAME_OR_PASSWORD.getCode());
        result.setMsg("账号或密码为空");
        return result;
    }
    public static <T> Result noUserNameOrPasswordOrGithubUrl(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO__USERNAME_OR_PASSWORD_OR_GITHUB_URL.getCode());
        result.setMsg("账号或密码或github地址为空");
        return result;
    }
    public static <T> Result noFindUserName(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO_FIND_USERNAME.getCode());
        result.setMsg("用户不存在");
        return result;
    }
    public static <T> Result errorPassword(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.ERROR_PASSWORD.getCode());
        result.setMsg("密码错误");
        return result;
    }
    public static <T> Result noTitle(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO_TITLE.getCode());
        result.setMsg("标题不能为空");
        return result;
    }
    public static <T> Result noContent(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO_CONTENT.getCode());
        result.setMsg("文章内容不能为空");
        return result;
    }

    public static <T> Result noCaptcha() {
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NO_CAPTCHA.getCode());
        result.setMsg("验证码为空");
        return result;

    }

    public static <T> Result errorCaptcha(boolean b) {
        Result<Boolean> result = new Result<>();
        result.setCode(ResultCodeEnum.ERROR_CAPTCHA.getCode());
        result.setMsg("验证码错误");
        result.setData(b);
        return result;
    }

    public static <T> Result overTimeCaptcha(boolean b) {
        Result<Boolean> result = new Result<>();
        result.setCode(ResultCodeEnum.OVER_TIME_CAPTCHA.getCode());
        result.setMsg("验证码超时, 请点击验证码刷新");
        result.setData(b);
        return result;
    }
}
